<?php
class Topico extends AppModel {

	var $name = 'Topico';
	var $primaryKey = 'topico';
	var $validate = array(
		'titulo' => array(
			'isUnique' => array(
				'rule' => 'isUnique',
				'required' => true,
				'message' => 'El titulo del topico ya existe'),
			'notEmpty' => array(	
				'rule' => 'notEmpty',
				'required' => true,
				'message' => 'El titulo del topico no puede estar vacio')
			)
	);

	//The Associations below have been created with all possible keys, those that are not needed can be removed
	var $belongsTo = array(
			'User' => array('className' => 'User',
								'foreignKey' => 'user_id',
								'conditions' => '',
								'fields' => '',
								'order' => ''
			),
			'Tema' => array('className' => 'Tema',
								'foreignKey' => 'tema_id',
								'conditions' => '',
								'fields' => '',
								'order' => ''
			)
	);

	var $hasMany = array(
			'Post' => array('className' => 'Post',
								'foreignKey' => 'topico_id',
								'dependent' => false,
								'conditions' => '',
								'fields' => '',
								'order' => '',
								'limit' => '',
								'offset' => '',
								'exclusive' => '',
								'finderQuery' => '',
								'counterQuery' => ''
			)
	);
	
	function cantPostsTodosTopicos($temaId){
		//me trae todos los temas en el foro, me trae su id y su nombre
		$topicos = $this->find('list',array('conditions' => array('Topico.tema_id =' => $temaId)));
		//print_r($topicos);		       
		foreach ($topicos as $topicoid){
			$lista[$topicoid]= $this->Post->find('count',array('conditions' => array('Post.topico_id =' => $topicoid)));
		}
		return $lista; //devuelve un array(index => valor)
			// donde "index" es el TopicoId y "valor" es la cantidad de posts que posee dicho TopicoId 
	}
}
?>